
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key = const Key('any_key')}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HttpDemo(),
    );
  }
}

class HttpDemo extends StatefulWidget {
  HttpDemo({Key key = const Key('any_key')}) : super(key: key);

  _HttpDemoState createState() => _HttpDemoState();
}

class _HttpDemoState extends State<HttpDemo> {
  List _list = [];

  @override
  void initState() {
    super.initState();
    this._getData();
  }

  _getData() async {
    var apiUrl =
        "https://mock.mengxuegu.com/mock/604b722bf340b05bceda401a/example/tvlist";
    Response result = await Dio().get(apiUrl);
    // print(result);
    // print(json.decode(result.data)["RECORDS"]);
    setState(() {
      // this._list = json.decode(result.data)["RECORDS"];
      this._list = result.data["RECORDS"];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("TV Online"),
        ),
        body: this._list.length > 0
            ? ListView(
                children: this._list.map((value) {
                  return Container(
                    child: ListTile(
                      title: Text(value["频道"]),
                    ),
                  );
                }).toList(),
              )
            : Text("加载中..."));
  }


}
